package cn.youwan.market.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class PromotionListbean {
	private List<FocusBean> focus;
	private List<SpecialBean> specials;
	private List<Appbean> apps;

	public PromotionListbean(String message) {
		specials = new ArrayList<PromotionListbean.SpecialBean>();
		apps = new ArrayList<PromotionListbean.Appbean>();
		focus = new ArrayList<PromotionListbean.FocusBean>();
		try {
			JSONObject json = new JSONObject(message);
			if (!json.isNull("focus")) {
				JSONArray array = json.optJSONArray("focus");
				for (int z = 0; z < array.length(); z++) {
					focus.add(new FocusBean(array.getJSONObject(z)));
				}
			}
			if (!json.isNull("recommend")) {
				JSONArray array1 = json.optJSONArray("recommend");
				for (int i = 0; i < array1.length(); i++) {
					specials.add(new SpecialBean(array1.getJSONObject(i)));
				}
			}
			if (!json.isNull("app_list")) {
				JSONArray array2 = json.optJSONObject("app_list").optJSONArray(
						"data");
				for (int j = 0; j < array2.length(); j++) {
					apps.add(new Appbean(array2.getJSONObject(j)));
				}
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
	}

	public List<SpecialBean> getSpecials() {
		return specials;
	}

	public void setSpecials(List<SpecialBean> specials) {
		this.specials = specials;
	}

	public List<Appbean> getApps() {
		return apps;
	}

	public void setApps(List<Appbean> apps) {
		this.apps = apps;
	}

	public List<FocusBean> getFocus() {
		return focus;
	}

	public void setFocus(List<FocusBean> focus) {
		this.focus = focus;
	}

	final static public class FocusBean {
		private String type;
		private String url;
		private String id;
		private int wid;
		private int hig;
		private String durl;
		private int dwid;
		private int dhig;

		public FocusBean(JSONObject j) {
			this.type = j.optString("type");
			this.id = j.optString("id");
			this.durl = j.optString("detailImg");
			this.dwid = j.optInt("detailImgW");
			this.dhig = j.optInt("detailImgH");
			this.url = j.optString("img");
			this.wid = j.optInt("width");
			this.hig = j.optInt("height");
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public int getWid() {
			return wid;
		}

		public void setWid(int wid) {
			this.wid = wid;
		}

		public int getHig() {
			return hig;
		}

		public void setHig(int hig) {
			this.hig = hig;
		}

		public String getDurl() {
			return durl;
		}

		public void setDurl(String durl) {
			this.durl = durl;
		}

		public int getDwid() {
			return dwid;
		}

		public void setDwid(int dwid) {
			this.dwid = dwid;
		}

		public int getDhig() {
			return dhig;
		}

		public void setDhig(int dhig) {
			this.dhig = dhig;
		}

	}

	final static public class SpecialBean {
		private String type;
		private String type1;
		private String type2;
		private String url;
		private String url1;
		private String id;
		private String id1;
		private int wid;
		private int hig;

		public SpecialBean(JSONObject j) {
			this.type = j.optString("type");
			this.type1 = j.optString("type1");
			this.type2 = j.optString("type2");
			this.url = j.optString("img1");
			this.url1 = j.optString("img2");
			this.id = j.optString("id1");
			this.id1 = j.optString("id2");
			this.wid = j.optInt("width");
			this.hig = j.optInt("height");
		}

		public int getWid() {
			return wid;
		}

		public void setWid(int wid) {
			this.wid = wid;
		}

		public int getHig() {
			return hig;
		}

		public void setHig(int hig) {
			this.hig = hig;
		}

		public String getType1() {
			return type1;
		}

		public void setType1(String type1) {
			this.type1 = type1;
		}

		public String getType2() {
			return type2;
		}

		public void setType2(String type2) {
			this.type2 = type2;
		}

		public String getId1() {
			return id1;
		}

		public void setId1(String id1) {
			this.id1 = id1;
		}

		public String getUrl1() {
			return url1;
		}

		public void setUrl1(String url1) {
			this.url1 = url1;
		}

		public String getType() {
			return type;
		}

		public void setType(String type) {
			this.type = type;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}
	}

	final static public class Appbean implements Serializable {
		private String id;
		private String pkg;
		private int version;
		private String versionName;
		private String appName;
		private String appCompany;
		private String appIcon;
		//分数
		private float rate;
		private boolean isPromotion;
		//对应app下载地址
		private String url;
		// 0 可下载
		// 1 可升级
		// 2 下载中
		// 3 可安装 即已经下载未安装
		// 4 可打开
		// 5 暂停
		// 6 下载等待中...
		private int downState;

		private int appSize;
		private List<String> photos;
		private String summer;
		private String appUpdate;
		private String appCode;
		private int commentNum;
		private int downNum;

		private int progress; // 下载进度
		private Object date;
		private String score;
		private String downloadCount;
		private String game_id;
		private String state;
		private String introduce;
		private String plugUrl;
		private String fileSize;
		private List<RaidersBean> raiders=new ArrayList<PromotionListbean.Appbean.RaidersBean>();
		//private ArrayList<RaidersBean> raiders=new ArrayList<PromotionListbean.Appbean.RaidersBean>();

		public Appbean() {
		}

		public Appbean(JSONObject j) throws JSONException {
			this.id = j.optString("g_id");
			this.game_id=j.optString("game_id");
			this.appName = j.optString("gameName");
			this.appIcon = j.optString("iconUrl");
			this.rate = Float.parseFloat(j.optString("score"));
			//this.appCompany = j.optString("owner");
			this.url = j.optString("url");
			this.plugUrl = j.optString("plugUrl");
			this.pkg = j.optString("packageName");
			//this.appSize = j.optInt("size");
			//			this.commentNum = j.optInt("comment_num");
			//			photos = new ArrayList<String>();
			//			try {
			//				if (!j.isNull("photos")) {
			//					JSONArray array = j.optJSONArray("photos");
			//					for (int i = 0; i < array.length(); i++) {
			//						photos.add(array.getString(i));
			//					}
			//				}
			//			} catch (Exception e) {
			//				e.printStackTrace();
			//			}
			//this.summer = j.optString("summary");
			this.versionName = j.optString("versionName");
			//this.appUpdate = j.optString("app_udate");
			this.appCode = j.optString("versionCode");
			//this.downNum = j.optInt("app_down_num");
			this.downState = -1;
			this.date=j.opt("date");
			this.downloadCount=j.getString("downloadCount");
			this.state=j.getString("state");
			this.introduce=j.getString("introduce");
			this.fileSize=j.getString("fileSize");
			String arr = j.getString("raiders");
			if(!arr.equals("")) {
				JSONArray raider = new JSONArray(arr);
				for(int i = 0; i < raider.length(); i++){
					JSONObject r = (JSONObject) raider.get(i);
					this.raiders.add(new RaidersBean(r));
				}
			}

		}

		public String getId() {
			return id;
		}

		public void setId(String id) {
			this.id = id;
		}

		public int getAppSize() {
			return appSize;
		}

		public void setAppSize(int appSize) {
			this.appSize = appSize;
		}

		public List<String> getPhotos() {
			return photos;
		}

		public void setPhotos(List<String> photos) {
			this.photos = photos;
		}

		public String getSummer() {
			return summer;
		}

		public void setSummer(String summer) {
			this.summer = summer;
		}

		public String getAppUpdate() {
			return appUpdate;
		}

		public void setAppUpdate(String appUpdate) {
			this.appUpdate = appUpdate;
		}

		public String getAppCode() {
			return appCode;
		}

		public void setAppCode(String appCode) {
			this.appCode = appCode;
		}

		public int getCommentNum() {
			return commentNum;
		}

		public void setCommentNum(int commentNum) {
			this.commentNum = commentNum;
		}

		public int getDownNum() {
			return downNum;
		}

		public void setDownNum(int downNum) {
			this.downNum = downNum;
		}

		public String getVersionName() {
			return versionName;
		}

		public void setVersionName(String versionName) {
			this.versionName = versionName;
		}

		public int getDownState() {
			return downState;
		}

		public String getAppIcon() {
			return appIcon;
		}

		public void setAppIcon(String appIcon) {
			this.appIcon = appIcon;
		}

		public void setDownState(int downState) {
			this.downState = downState;
		}

		public String getPkg() {
			return pkg;
		}

		public void setPkg(String pkg) {
			this.pkg = pkg;
		}

		public int getVersion() {
			return version;
		}

		public void setVersion(int version) {
			this.version = version;
		}

		public String getAppName() {
			return appName;
		}

		public void setAppName(String appName) {
			this.appName = appName;
		}

		public String getAppCompany() {
			return appCompany;
		}

		public void setAppCompany(String appCompany) {
			this.appCompany = appCompany;
		}

		public float getRate() {
			return rate;
		}

		public void setRate(float rate) {
			this.rate = rate;
		}

		public boolean isPromotion() {
			return isPromotion;
		}

		public void setPromotion(boolean isPromotion) {
			this.isPromotion = isPromotion;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public int getProgress() {
			return progress;
		}

		public void setProgress(int progress) {
			this.progress = progress;
		}

		public Object getDate() {
			return date;
		}

		public void setDate(Object date) {
			this.date = date;
		}

		public String getScore() {
			return score;
		}

		public void setScore(String score) {
			this.score = score;
		}

		public String getDownloadCount() {
			return downloadCount;
		}

		public void setDownloadCount(String downloadCount) {
			this.downloadCount = downloadCount;
		}

		public String getGame_id() {
			return game_id;
		}

		public void setGame_id(String game_id) {
			this.game_id = game_id;
		}

		public String getState() {
			return state;
		}

		public void setState(String state) {
			this.state = state;
		}

		public String getIntroduce() {
			return introduce;
		}

		public void setIntroduce(String introduce) {
			this.introduce = introduce;
		}

		public String getPlugUrl() {
			return plugUrl;
		}

		public void setPlugUrl(String plugUrl) {
			this.plugUrl = plugUrl;
		}

		public String getFileSize() {
			return fileSize;
		}

		public void setFileSize(String fileSize) {
			this.fileSize = fileSize;
		}

		public List<RaidersBean> getRaiders() {
			return raiders;
		}

		public void setRaiders(List<RaidersBean> raiders) {
			this.raiders = raiders;
		}

		@Override
		public String toString() {
			return "Appbean [id=" + id + ", pkg=" + pkg + ", version="
					+ version + ", versionName=" + versionName + ", appName="
					+ appName + ", appCompany=" + appCompany + ", appIcon="
					+ appIcon + ", rate=" + rate + ", isPromotion="
					+ isPromotion + ", url=" + url + ", downState=" + downState
					+ ", appSize=" + appSize + ", photos=" + photos
					+ ", summer=" + summer + ", appUpdate=" + appUpdate
					+ ", appCode=" + appCode + ", commentNum=" + commentNum
					+ ", downNum=" + downNum + ", progress=" + progress
					+ ", date=" + date + ", score=" + score
					+ ", downloadCount=" + downloadCount + ", game_id="
					+ game_id + ", state=" + state + ", introduce=" + introduce
					+ ", plugUrl=" + plugUrl + ", fileSize=" + fileSize
					+ ", raiders=" + raiders + "]";
		}



		final static public class RaidersBean implements Serializable{
			private String title;
			private String url;
			public String getTitle() {
				return title;
			}
			public void setTitle(String title) {
				this.title = title;
			}
			public String getUrl() {
				return url;
			}
			public void setUrl(String url) {
				this.url = url;
			}
			public RaidersBean(JSONObject j) throws JSONException {
				super();
				this.title = j.getString("title");
				this.url = j.getString("url");
			}
			public RaidersBean() {
				super();
			}
			@Override
			public String toString() {
				return "RaidersBean [title=" + title + ", url=" + url + "]";
			}

		}
	}


}
